/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package domain;

import java.io.IOException;
import java.util.Iterator;
import presentation.Client;
import presentation.GuiController;
import domain.exceptions.CannotPlaceAgentHereException;

/**
 *
 * @author shaigi
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws CannotPlaceAgentHereException {

    	String 	assinment 		  = args[0];
    	Board 	board 			  = null;
    	boolean deterministicMode = false;
    	boolean zeroSumMode		  = false;
    	int		arsenal			  = 0;

    	System.out.println("Ass: " + assinment);
        /**
         * Initlization
         */

    	GuiController present = new GuiController();
    	present.start();

    	// initialize game (but without agents yet):
        /************* For Assignment 1 *************/
        ///*
        if (assinment.equals("1")){
	        //board 				= new Board("board_Ass1.txt", assinment);
        	board 				= new Board("board_Ass1_b.txt", assinment);
	        deterministicMode 	= true;
	        zeroSumMode 		= false;
	        arsenal 			= 0;	// It doesn't matter in assignment 1
        }
        //*/


        /************* For Assignment 2 *************/
        // 1. Deterministic zero-sum, optimal agent using mini-max with alph-beta pruning:
        if (assinment.equals("2.1")){
        	board 				= new Board("board_Ass2.1.txt", assinment);
        	//board	 			= new Board("board_Ass2.1_a.txt", assinment);
	        deterministicMode 	= true;
	        zeroSumMode 		= true;
	        arsenal				= 3;
        }

        // 2. Deterministic non-zero-sum, optimal agent using maxi-max with alph-beta pruning:
        if (assinment.equals("2.2")){
        	board 				= new Board("board_Ass2.2.txt", assinment);
        	deterministicMode 	= true;
        	zeroSumMode 		= false;
        	arsenal				= 3;
        }

        // 3. Non-Deterministic zero-sum, optimal agent using expecti-mini-max with alph-beta pruning:
        if (assinment.equals("2.3")){
        	// for Board2.3_a:
        	board 				= new Board("board_Ass2.3_a.txt", assinment);
        	deterministicMode 	= false;
        	zeroSumMode 		= true;
        	arsenal				= 3;

        	// for Board2.3_b:
//        	board 				= new Board("board_Ass2.3_b.txt", assinment);
//        	deterministicMode 	= false;
//        	zeroSumMode 		= true;
//        	arsenal				= 3;

        }

        Game game = new Game(board, deterministicMode, zeroSumMode, arsenal, assinment);

        // initialize gui:
        Client c = new Client(game);

        game.initialize();

        // subscribe client for all agents:
        for (Iterator<Agent> it = Game.getAgents().iterator(); it.hasNext();) {
            Agent agent = it.next();
            agent.subscribe(c);
        }
        game.placeAgents();

        game.start();
        Debug.println("done....");

        try {	c.sendMessage("stop");		} catch (IOException e) {	e.printStackTrace();}
        present.stopTheGame();
    }

}
